cc.Class({
    extends: cc.Component,

    ctor: function (game) {
		
		this.game = game;
		
		this.toStepToSpe = cc.callFunc(function () {
				this.stepToSpe();
		}, this); 
		
		this.toAfterSpe = cc.callFunc(function () {
				this.afterSpe();
		}, this); 

		this.toBeforeStep = cc.callFunc(function () {
				this.beforeStep();
		}, this); 
	},
	
	//奖励时间入口
	startReward(){
		this.game.node.runAction(cc.sequence(cc.delayTime(1.4),this.toBeforeStep));
	},
	
	//第一次特殊块消除完毕入口
	disappearDuringReward(){
		this.game.node.runAction(cc.sequence(cc.delayTime(1.4),this.toAfterSpe));
	},
	
	//奖励结束 游戏结束
	realGameOver(){
		this.game.effectMast.active = true;
		this.game.showMessage("游戏结束");
		this.game.node.runAction(cc.sequence(cc.delayTime(1.4),this.game.toScoreCallback));
	},
	
	//第一次特殊块消除完毕后判断是否有剩余步数
	afterSpe(){
		
		if(!this.game.gameManager.disappearSpe()){
				if(this.game.happyTime==1){
						
						if(this.game.playerType==2){//竞速模式跳过步数奖励
							this.realGameOver();
						}else{
							this.game.happyTime=2;
							this.stepToSpe();
						}
						
				}else if(this.game.happyTime==2){
						
						this.realGameOver();
						
				}
		}
		
	},
	
	//判断剩余步数之前先消除特殊块
	beforeStep(){
		
		if(this.game.playerType==2){
			this.game.messageDisplay.node.setPosition(-400,0);
		}
		
		if(!this.game.gameManager.disappearSpe()){//如果没有特殊块 则进入步数奖励
			if(this.game.lastStep>0&&this.game.playerType==3){
				this.game.happyTime=2;
				this.stepToSpe();
			}else{
				this.game.toScoreUI();
			}
		}
		
	},
	
	//步数转化为分数奖励
	stepToSpe(){
		
		this.game.effectMast.active = true;
		
		if(this.starnode1){
			this.game.effectTop.removeChild(this.starnode1);
		}
		
		if(this.tempMp){
			this.tempMp.resetType2(Math.floor(Math.random()*6)+2);
			this.game.node.removeChild(this.tempMp.blockNode);
			this.game.effectTop.addChild(this.tempMp.blockNode);
		}
		
		
		
		if(this.game.lastStep>0){
			this.game.lastStep--;
			
			this.tempMp = null;
			
			do{
				
				this.tempMp = this.game.mapPointArr[Math.floor(Math.random()*this.game.mapPointArr.length)];
				
			}while(this.tempMp.type2>1);
			
			this.starnode1 = this.game.effectManager.createOneceEffect(this.tempMp,this.game,-180,300,0.2);
			
			this.game.node.runAction(cc.sequence(cc.delayTime(0.2),this.toStepToSpe));
		}else{
			if(!this.game.gameManager.disappearSpe()){
				this.game.toScoreUI();
			}
		}
		
	},
});
